package com.aurora.blog.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aurora.common.log.annotation.Log;
import com.aurora.common.log.enums.BusinessType;
import com.aurora.common.security.annotation.RequiresPermissions;
import com.aurora.blog.domain.BlogShares;
import com.aurora.blog.service.IBlogSharesService;
import com.aurora.common.core.web.controller.BaseController;
import com.aurora.common.core.web.domain.AjaxResult;
import com.aurora.common.core.utils.poi.ExcelUtil;
import com.aurora.common.core.web.page.TableDataInfo;

/**
 * 分享Controller
 * 
 * @author aurora
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/blogShares")
public class BlogSharesController extends BaseController
{
    @Autowired
    private IBlogSharesService blogSharesService;

    /**
     * 查询分享列表
     */
    @RequiresPermissions("blog:blogShares:list")
    @GetMapping("/list")
    public TableDataInfo list(BlogShares blogShares)
    {
        startPage();
        List<BlogShares> list = blogSharesService.selectBlogSharesList(blogShares);
        return getDataTable(list);
    }

    /**
     * 导出分享列表
     */
    @RequiresPermissions("blog:blogShares:export")
    @Log(title = "分享", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogShares blogShares)
    {
        List<BlogShares> list = blogSharesService.selectBlogSharesList(blogShares);
        ExcelUtil<BlogShares> util = new ExcelUtil<BlogShares>(BlogShares.class);
        util.exportExcel(response, list, "分享数据");
    }

    /**
     * 获取分享详细信息
     */
    @RequiresPermissions("blog:blogShares:query")
    @GetMapping(value = "/{shareId}")
    public AjaxResult getInfo(@PathVariable("shareId") Long shareId)
    {
        return success(blogSharesService.selectBlogSharesByShareId(shareId));
    }

    /**
     * 新增分享
     */
    @RequiresPermissions("blog:blogShares:add")
    @Log(title = "分享", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogShares blogShares)
    {
        return toAjax(blogSharesService.insertBlogShares(blogShares));
    }

    /**
     * 修改分享
     */
    @RequiresPermissions("blog:blogShares:edit")
    @Log(title = "分享", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogShares blogShares)
    {
        return toAjax(blogSharesService.updateBlogShares(blogShares));
    }

    /**
     * 删除分享
     */
    @RequiresPermissions("blog:blogShares:remove")
    @Log(title = "分享", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shareIds}")
    public AjaxResult remove(@PathVariable Long[] shareIds)
    {
        return toAjax(blogSharesService.deleteBlogSharesByShareIds(shareIds));
    }
}
